package com.woniu.cq.medical.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.cq.medical.dao.mymapper.My_PatientMapper;
import com.woniu.cq.medical.entity.Patient;
import com.woniu.cq.medical.dao.PatientMapper;
import com.woniu.cq.medical.service.PatientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-09-05
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {
    @Autowired
    private My_PatientMapper myPatientMapper;

    @Override
    public Patient selectPatientByIdCard(String idCard) {
        return myPatientMapper.selectPatientByIdCard(idCard);
    }

    @Override
    public IPage<Patient> selectAll(int pageIdx, int pageSize, String name) {
        Page<Patient> page = new Page<>(pageIdx,pageSize);

        IPage<Patient> pageResult =  myPatientMapper.selectAll(page,name);
        return pageResult;
    }

    @Override
    public void updateByIdPatient(Patient patient) {
        myPatientMapper.updateById(patient);
    }

    @Override
    public void addPatient(Patient patient) {
        myPatientMapper.insert(patient);
    }


    /**
     * 查询身份证ID是否重复
     * @param patientIdCard
     * @return
     */
    @Override
    public Patient queryCardIdRepetition(String patientIdCard) {
        Patient patient = myPatientMapper.queryCardIdRepetition(patientIdCard);
       return patient;
    }

    /**
     * 因为挂号新增身份证ID和姓名
     * @param patient
     * @return
     */
    @Override
    public int insertPatient(Patient patient) {
        int insert = myPatientMapper.insert(patient);
        return insert;
    }


}
